from tdxpy.hq import TdxHq_API

# 备选服务器列表
servers = [
    ("120.79.60.82", 7709),
    ("47.107.75.159", 7709),
    ("119.29.201.30", 7709),
    ("58.251.33.227", 443),  # 尝试443端口
]

api = TdxHq_API()
connected = False

for ip, port in servers:
    try:
        with api.connect(ip, port):
            print(f"成功连接到服务器：{ip}:{port}")
            # 这里替换为你的实际代码
            api.disconnect()
            connected = True
            break
    except Exception as e:
        print(f"连接 {ip}:{port} 失败: {e}")

if not connected:
    print("所有服务器尝试均失败")